<?php
namespace app\common\model\mysql;

use think\Model;
class GoodsSku extends ModelBase{
	// 指定数据库表
	public $table = 'mall_goods_sku';

	public function goods(){
		return $this->hasOne(Goods::class,'id','goods_id'); 
	}

	public function getNormalByGoodsId($goodsId){
		$where = [
			'goods_id' => $goodsId,
			'status' => config('status.mysql.normal'),
		];
		
		return $this->where($where)->select();
	}

	//减少库存
	public function decStock($id,$num){
		$res = $this->where('id','=',$id)
			->dec('stock',$num)
			->update();

		return $res;
	}
}